#ifndef HTTP_PARSER_H
#define HTTP_PARSER_H

#include <sparrow/http_header_callback.h>

class HttpParser
{
    public:
        HttpParser(HttpHeaderCallback *cb);
        bool parse_request(const Octets &input, Octets &reminder);
        bool parse_response(const Octets &input, Octets &reminder);

        static void parse_uri(const Slice &uri, 
                Slice &schema,
                Slice &user_info,
                Slice &host,
                int &port,
                Slice &path,
                Slice &query,
                Slice &fragment);

        static void parse_version(const Slice &version, int &major, int &minor);

    private:
        bool accumulate(const Octets &input, Octets &reminder);
        void parse_request_line();
        void parse_status_line();
        void parse_headers();
        void parse_header(const Slice &header);

        typedef Octets::const_iterator _oci;
        HttpHeaderCallback *cb_;
        Octets original_buffer_;
        _oci current;
};

#endif // HTTP_PARSER_H

